package com.bite.rabbitmq.rabbitopsdemo.controller;


import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/consumer")
@RestController
// 拉的方式获取
public class ConsumerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    @RequestMapping("/get")
    public String get() {
        Message msg = rabbitTemplate.receive("cluster.queue");
        System.out.println("[cluster.queue] 收到消息： " + msg);
        return "获取消息成功";
    }
}
